<!-- begin _includes/seo.html -->
{%- assign title_separator = site.title_separator | default: '-' -%}

{%- assign page_title = page.title | default: site.title | replace: '|', '&#124;' -%}
{%- assign seo_title = page_title | append: " " | append: title_separator | append: " " | append: site.title | replace: '|', '&#124;' -%}

{%- assign page_title = page_title | markdownify | strip_html | strip_newlines | escape_once -%}
{%- assign seo_title  = seo_title  | markdownify | strip_html | strip_newlines | escape_once -%}

{%- assign canonical_url = page.canonical_url | default: page.url | replace: "/index.html", "/" | absolute_url %}

{%- assign seo_description = page.description | default: page.excerpt | default: site.description -%}
{%- if seo_description -%}
  {%- assign seo_description = seo_description | markdownify | strip_html | newline_to_br | strip_newlines | replace: '<br />', ' ' | escape_once | strip -%}
{%- endif -%}

{%- assign author = page.author | default: page.authors[0] | default: site.author -%}
{%- assign author = site.data.authors[author] | default: author -%}

{%- if author.twitter -%}
  {%- assign author_twitter = author.twitter | replace: "@", "" -%}
{%- endif -%}

{%- assign page_large_image = page.header.og_image | default: page.header.overlay_image | default: page.header.image | absolute_url | escape -%}
{%- assign page_teaser_image = page.header.teaser | default: site.og_image | absolute_url | escape -%}
{%- assign site_og_image = site.og_image | absolute_url | escape -%}

{%- if page.date -%}
  {%- assign og_type = "article" -%}
{%- else -%}
  {%- assign og_type = "website" -%}
{%- endif -%}

<title>{{ seo_title }}{% if paginator %}{% unless paginator.page == 1 %} {{ title_separator }} {{ site.data.ui-text[site.locale].page | default: "Page" }} {{ paginator.page }}{% endunless %}{% endif %}</title>
<meta name="description" content="{{ seo_description }}">

{% if author.name %}
  <meta name="author" content="{{ author.name | default: author }}">
  {% if og_type == "article" %}
  <meta property="article:author" content="{{ author.name | default: author }}">
  {% endif %}
{% endif %}

<meta property="og:type" content="{{ og_type }}">
<meta property="og:locale" content="{{ site.locale | replace: "-", "_" | default: "en_US" }}">
<meta property="og:site_name" content="{{ site.title }}">
<meta property="og:title" content="{{ page_title }}">
<meta property="og:url" content="{{ canonical_url }}">

{% if seo_description %}
  <meta property="og:description" content="{{ seo_description }}">
{% endif %}

{% if page_large_image %}
  <meta property="og:image" content="{{ page_large_image }}">
{% elsif page_teaser_image %}
  <meta property="og:image" content="{{ page_teaser_image }}">
{% endif %}

{% if site.twitter.username %}
  <meta name="twitter:site" content="@{{ site.twitter.username | replace: "@", "" }}">
  <meta name="twitter:title" content="{{ page_title }}">
  <meta name="twitter:description" content="{{ seo_description }}">
  <meta name="twitter:url" content="{{ canonical_url }}">

  {% if page_large_image %}
    <meta name="twitter:card" content="summary_large_image">
    <meta name="twitter:image" content="{{ page_large_image }}">
  {% else %}
    <meta name="twitter:card" content="summary">
    {% if page_teaser_image %}
      <meta name="twitter:image" content="{{ page_teaser_image }}">
    {% endif %}
  {% endif %}

  {% if author_twitter %}
    <meta name="twitter:creator" content="@{{ author_twitter }}">
  {% endif %}
{% endif %}

{% if page.date %}
  <meta property="article:published_time" content="{{ page.date | date_to_xmlschema }}">
{% endif %}

{% if og_type == "article" and page.last_modified_at %}
  <meta property="article:modified_time" content="{{ page.last_modified_at | date_to_xmlschema }}">
{% endif %}

{% if site.facebook %}
  {% if site.facebook.publisher %}
    <meta property="article:publisher" content="{{ site.facebook.publisher }}">
  {% endif %}

  {% if site.facebook.app_id %}
    <meta property="fb:app_id" content="{{ site.facebook.app_id }}">
  {% endif %}
{% endif %}

<link rel="canonical" href="{{ canonical_url }}">

{% if paginator.previous_page %}
  <link rel="prev" href="{{ paginator.previous_page_path | absolute_url }}">
{% endif %}
{% if paginator.next_page %}
  <link rel="next" href="{{ paginator.next_page_path | absolute_url }}">
{% endif %}

{% if page.url == '/' %}
  {% include schema.html %}
{% endif %}

{% if site.google_site_verification %}
  <meta name="google-site-verification" content="{{ site.google_site_verification }}" />
{% endif %}
{% if site.bing_site_verification %}
  <meta name="msvalidate.01" content="{{ site.bing_site_verification }}">
{% endif %}
{% if site.alexa_site_verification %}
  <meta name="alexaVerifyID" content="{{ site.alexa_site_verification }}">
{% endif %}
{% if site.yandex_site_verification %}
  <meta name="yandex-verification" content="{{ site.yandex_site_verification }}">
{% endif %}
{% if site.naver_site_verification %}
  <meta name="naver-site-verification" content="{{ site.naver_site_verification }}">
{% endif %}
{% if site.baidu_site_verification %}
  <meta name="baidu-site-verification" content="{{ site.baidu_site_verification }}">
{% endif %}
<!-- end _includes/seo.html -->
